// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import { ReletApplyList } from '../domains/reletapply.domain';
import {ReletApply} from '../domains/reletapply.domain';

/**
 *
 */
@Injectable({
  providedIn: 'root'
})
export class ReletApplyServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'reletApplyServiceSvr.assx/';
  }


  updateReletApply(token: string, id: string, state: number): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString())
      .append('state', state.toString());
    return this.request.post<number>(this.baseUrl + 'updateReletApply', httpParams).then((res) => {
      return res;
    });
  }


  checkIsRedo(token: string, customerId: string, houseId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('houseId', houseId.toString());
    return this.request.post<number>(this.baseUrl + 'checkIsRedo', httpParams).then((res) => {
      return res;
    });
  }


  listReletApply(token: string, customerId: string, state: number, isBackout: string, community: string, customerName: string, flag: number, skip: number, size: number): Promise<ReletApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('state', state.toString())
      .append('isBackout', isBackout.toString())
      .append('community', community.toString())
      .append('customerName', customerName.toString())
      .append('flag', flag.toString())
      .append('skip', skip.toString())
      .append('size', size.toString());
    return this.request.post<ReletApplyList>(this.baseUrl + 'listReletApply', httpParams).then((res) => {
      return new ReletApplyList(res);
    });
  }


  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }


  saveReletApply(token: string, customerId: string, houseId: string, remark: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('houseId', houseId.toString())
      .append('remark', remark.toString());
    return this.request.post<number>(this.baseUrl + 'saveReletApply', httpParams).then((res) => {
      return res;
    });
  }


  deleteReletApply(token: string, id: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString());
    return this.request.post<number>(this.baseUrl + 'deleteReletApply', httpParams).then((res) => {
      return res;
    });
  }


  getReletApply(token: string, id: string): Promise<ReletApply> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('id', id.toString());
    return this.request.post<ReletApply>(this.baseUrl + 'getReletApply', httpParams).then((res) => {
      return new ReletApply(res);
    });
  }
}
